import { Inject, Provide } from '@midwayjs/core';
import { BaseService } from '@cool-midway/core';
import { ContentBannerService } from './banner';
import { ContentTileService } from './tile';
import { ContentArticleService } from './article';

@Provide()
export class ContentHomeService extends BaseService {
    @Inject()
    contentBannerService: ContentBannerService;

    @Inject()
    contentTileService: ContentTileService;

    @Inject()
    contentArticleService: ContentArticleService;

    /**
     * 首页聚合数据
     */
    async index() {
        const [banners, tiles, articlePage] = await Promise.all([
            this.contentBannerService.listOpen(),
            this.contentTileService.listOpen(),
            this.contentArticleService.pageOpen({ page: 1, size: 5 }), // 首页文章默认取前5条
        ]);

        return {
            banners,
            tiles,
            articles: articlePage.list, // 只要列表数据
        };
    }
}

